package com.example.cshaoshao.demo.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.example.cshaoshao.demo.R;

/**
 * Created by cshaoshao on 2017/6/29.
 */

public class SpinnerActivity extends AppCompatActivity {
    private ArrayAdapter<String> adapter;
    private Spinner spinnerCardNumber;
    private TextView editText;
    private String arr[];
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spinner);
        spinnerCardNumber= (Spinner) findViewById(R.id.spinner);
        editText= (TextView) findViewById(R.id.editText);
        arr=getResources().getStringArray(R.array.CardNumber);
        spinnerCardNumber.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(SpinnerActivity.this,"你选中了"+arr[position],Toast.LENGTH_SHORT).show();
                editText.setText(arr[position]);
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

    }
}
